import sys
from pathlib import Path

# 改变路径
current_folder = Path(__file__).absolute().parent
father_folder = str(current_folder.parent)
sys.path.append(father_folder)

from typing import List
from utils.文件夹下的所有文件 import getFilesList, getDirsList
from shutil import copyfile
from utils.JSON的输入和输出 import 读取json
from utils.创建文件夹 import Create_folder


def fetchIdsFile(all_names: List[str], target_dir: str) -> None:
    '''
    提取文件并且复制到目标目录
    '''
    game_root_path = "E://Program Files (x86)//Steam//steamapps//common//Yu-Gi-Oh!  Master Duel//LocalData//LocalDataFiles//0000"  # noqa

    all_dirs = getDirsList(game_root_path)

    all_file_paths = []

    for dir in all_dirs:
        for file in getFilesList(game_root_path + '/' + dir):
            if file in all_names:
                all_file_paths.append(game_root_path + '/' + dir + '/' + file)

    print(all_file_paths)

    # 将所有文件复制到一个新文件夹里面
    for path in all_file_paths:
        copyfile(path, target_dir + path.split('/')[-1])

Create_folder('data/IDS/日文')
Create_folder('data/IDS/英文')
fetchIdsFile(读取json('data/ids-map/assets_indepent.json')['日文'], 'data/IDS/日文/')
fetchIdsFile(读取json('data/ids-map/assets_indepent.json')['英文'], 'data/IDS/英文/')
